package exam.bak.netease;

import java.math.BigInteger;
import java.util.Scanner;

public class P3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger n = new BigInteger(scanner.nextLine().trim(), 10);
        long total = 0;
        long all = 0;
        byte[] bytes = n.toByteArray();
        String s = Integer.toBinaryString(bytes[0]);
        all += s.length();
        for (char c : s.toCharArray()) {
            if (c == '1') {
                total += 1;
            }
        }
        for (int i = 1; i < bytes.length; i++) {
            total += oneCount(bytes[i]);
            all += 8;
        }
        System.out.println(Math.min(total, all - total + 1));
    }

    public static int oneCount(byte b) {
        String str = Integer.toBinaryString(b);
        int total = 0;
        for (char c : str.toCharArray()) {
            if (c == '1') {
                total += 1;
            }
        }
        return total;
    }

    public void back() {
        Scanner scanner = new Scanner(System.in);
        BigInteger n = new BigInteger(scanner.nextLine().trim(), 10);
        BigInteger tmp = new BigInteger("1", 10);
        BigInteger zero = new BigInteger("0", 10);
        BigInteger two = new BigInteger("2", 10);

        long total = 0;
        long all = 0;
        while (n.compareTo(tmp) > 0) {
            if (tmp.and(n).compareTo(zero) > 0) {
                total++;
            }
            tmp = tmp.multiply(two);
            all++;
        }
        System.out.println(Math.min(total, all - total + 1));
    }
}
